import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueDevTools from 'vite-plugin-vue-devtools'
import { crx, defineManifest } from '@crxjs/vite-plugin'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import basicSsl from '@vitejs/plugin-basic-ssl'

const manifest = defineManifest({
  manifest_version: 3,
  name: '颜色管理器',
  version: '0.0.1',
  permissions: ['tabs', 'contextMenus', 'activeTab', 'scripting', 'storage'],
  icons: {
    16: 'icon-x16.png',
    32: 'icon-x32.png',
    48: 'icon-x48.png',
    128: 'icon-x48.png'
  },
  background: {
    type: 'module',
    service_worker: 'src/background/index.ts'
  },
  action: {},
  host_permissions: ['<all_urls>'],
  // content_security_policy: {},
  content_scripts: [
    {
      js: ['src/inject/main.ts'],
      matches: ['http://*/*', 'https://*/*'],
      exclude_matches: ['https://element-plus.gitee.io/*']
    }
  ]
})

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    // VueDevTools(),
    // basicSsl(),
    crx({ manifest }),
    AutoImport({ resolvers: [ElementPlusResolver()] }),
    Components({ resolvers: [ElementPlusResolver()] })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@shared': fileURLToPath(new URL('./src/shared', import.meta.url))
    }
  },
  server: {
    host: true
    // https: {}
  }
})
